cmake_minimum_required(VERSION 3.22)
project(Sofa.Component.Collision.Detection.Intersection LANGUAGES CXX)

set(SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR "src/sofa/component/collision/detection/intersection")

set(HEADER_FILES
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/config.h.in
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/init.h
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/BaseProximityIntersection.h
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/DiscreteIntersection.h
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/LocalMinDistance.h
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/MeshDiscreteIntersection.h
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/MeshDiscreteIntersection.inl
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/MeshMinProximityIntersection.h
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/MeshNewProximityIntersection.h
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/MeshNewProximityIntersection.inl
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/MinProximityIntersection.h
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/NewProximityIntersection.h
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/NewProximityIntersection.inl
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/RayDiscreteIntersection.h
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/RayDiscreteIntersection.inl
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/RayNewProximityIntersection.h
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/TetrahedronDiscreteIntersection.h
)

set(SOURCE_FILES
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/init.cpp
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/BaseProximityIntersection.cpp
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/DiscreteIntersection.cpp
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/LocalMinDistance.cpp
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/MeshDiscreteIntersection.cpp
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/MeshMinProximityIntersection.cpp
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/MeshNewProximityIntersection.cpp
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/MinProximityIntersection.cpp
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/NewProximityIntersection.cpp
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/RayDiscreteIntersection.cpp
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/RayNewProximityIntersection.cpp
    ${SOFACOMPONENTCOLLISIONDETECTIONINTERSECTION_SOURCE_DIR}/TetrahedronDiscreteIntersection.cpp
)

sofa_find_package(Sofa.Simulation.Core REQUIRED)
sofa_find_package(Sofa.Component.Collision.Geometry REQUIRED)

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${WRAPPER_FILES})
target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Simulation.Core)
target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Component.Collision.Geometry)

sofa_create_package_with_targets(
    PACKAGE_NAME ${PROJECT_NAME}
    PACKAGE_VERSION ${Sofa_VERSION}
    TARGETS ${PROJECT_NAME} AUTO_SET_TARGET_PROPERTIES
    INCLUDE_SOURCE_DIR "src"
    INCLUDE_INSTALL_DIR "${PROJECT_NAME}"
)

# Tests
# If SOFA_BUILD_TESTS exists and is OFF, then these tests will be auto-disabled
cmake_dependent_option(SOFA_COMPONENT_COLLISION_DETECTION_INTERSECTION_BUILD_TESTS "Compile the automatic tests" ON "SOFA_BUILD_TESTS OR NOT DEFINED SOFA_BUILD_TESTS" OFF)
if(SOFA_COMPONENT_COLLISION_DETECTION_INTERSECTION_BUILD_TESTS)
    enable_testing()
    add_subdirectory(tests)
endif()
